package cn.tx.three;

import cn.tx.RabbitMQUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

import java.io.IOException;

/**
 * fanout 发送者测试
 * @author Mxb
 * @version 1.0
 * @date 2020/10/4 17:13
 */
public class Producer {
    @Test
    public void sendMessage() throws IOException {
        Connection connection = RabbitMQUtils.getConnection();
        //创建通道
        Channel channel = connection.createChannel();
        //设置交换机
        // channel.exchangeDeclare("logs", "fanout");
        channel.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);
        //向交换机发消息
        channel.basicPublish("logs","",null,("我是个fanout 类型的消息").getBytes());

        RabbitMQUtils.closeChannelAndConnection(channel,connection);
        System.out.println("消费发送成功");
    }
}
